package com.lywz.core.fileUpload;

import java.io.File;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.FilenameUtils;

/**
 * 上传文件
 * 
 * @author Lionel pang
 * @date 2010-5-5
 * 
 */
public class UploadFile {

    // 所要上传的文件
    private File file;

    // 所要上传的文件类型
    private String path;

    // 文件格式
    private String formate;

    private int height;

    private int width;

    private String basePath;

    // 原始文件名称
    private String protypeFileName;

    public UploadFile(File file, String path, String protypeFileName, HttpServletRequest request){
        this(file, path, protypeFileName, 0, 0, request);
    }
    
    /**
     * 
     * @param file  需要上传的文件
     * @param path  保存文件的相对目录
     * @param protypeFileName   文件的原始文件名称
     * @param height    
     * @param width     
     * @param request   http的request对象
     */
    @SuppressWarnings("deprecation")
    public UploadFile(File file, String path, String protypeFileName, int height, int width,HttpServletRequest request){
        this.basePath = request.getRealPath("/") + "resource/";
        this.setFile(file);
        this.setProtypeFileName(protypeFileName);
        this.setPath(path);
        this.setHeight(height);
        this.setWidth(width);
    }

    public String getProtypeFileName() {
        return protypeFileName;
    }

    public void setProtypeFileName(String protypeFileName) {
        this.protypeFileName = protypeFileName;
        // 给文件格式加上文件后缀名
        this.formate = FilenameUtils.getExtension(protypeFileName);
    }

    public String getBasePath() {
        return basePath;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public String getFormate() {
        return formate;
    }

    @Deprecated
    public void setFormate(String formate) {
        this.formate = formate;
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = uploadBasePath + path;
    }

    // 上传文件默认文件夹
    private final static String uploadBasePath = "upload/";

}
